﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CodeCamp12.DAL;
using CodeCamp12.Domain;
using System.IO;
using log4net;

namespace CodeCamp12.BLL
{
    public class SpeakersBL
    {
        private ILog log = LogManager.GetLogger("CodeCamp12.BLL");
        
        /// <summary>
        /// Inserts new speaker for the website
        /// </summary>
        /// <param name="speaker"></param>
        /// <returns>string</returns>
        public string InsertSpeaker(Speaker speaker)
        {
            try
            {
                var speakerDataProvider = new SpeakerDataManagement();
                return speakerDataProvider.InsertSpeaker(speaker).ToString();
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }

           
        }

        /// <summary>
        /// Inserts document for speaker
       /// </summary>
       /// <param name="document"></param>
        public void InsertDocumentForSpeaker(Domain.File document)
        {
           
            try
            {
                var fileDataProvider = new FileDataManagement();
                fileDataProvider.InsertFile(document);
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
            
        }

        /// <summary>
        /// Gets all speakers for the site
        /// </summary>
        /// <returns>Speaker</returns>
        public List<Speaker> GetAllSpeakers()
        {
            try
            {
                var speakerDataProvider = new SpeakerDataManagement();
                return  speakerDataProvider.GetAllSpeakers();
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }

            
        }

        /// <summary>
        /// Returns the speakers for the current code camp event
        /// </summary>
        /// <returns></returns>
        public List<Speaker> GetSpeakersForCurrent()
        {
            
            try
            {
                var speakerDataProvider = new SpeakerDataManagement();
                return speakerDataProvider.GetSpeakersForCurrent();
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
          
        }

        /// <summary>
        /// Returns all speakers for event with id passed in parametars
        /// </summary>
        /// <param name="eventId"></param>
        /// <returns></returns>
        public List<Speaker> GetSpeakersForEvent(Guid eventId)
        {
            try
            {
                var speakerDataProvider = new SpeakerDataManagement();
                return speakerDataProvider.GetSpeakersForEvent(eventId);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }
        }

        /// <summary>
        /// Deletes speaker from website
        /// </summary>
        /// <param name="speaker"></param>
        public void DeleteSpeaker(Speaker speaker)
        {
            
            var speakerDataProvider = new SpeakerDataManagement();
            var fileDataManagement = new FileDataManagement();
            try
            {
               speakerDataProvider.DeleteSpeaker(speaker);
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
        }

        /// <summary>
        /// Updates existing speaker speaker
        /// </summary>
        /// <param name="speaker"></param>
        public void UpdateSpeaker(Speaker speaker)
        {
            var speakerDataProvider = new SpeakerDataManagement();
            try
            {
                speakerDataProvider.UpdateSpeaker(speaker);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }
        }

        /// <summary>
        /// Updates document for speaker
        /// </summary>
        /// <param name="document"></param>
        public void UpdateDocumentForSpeaker(Domain.File document)
        {
            try
            {
                var fileDataManagement = new FileDataManagement();
                fileDataManagement.UpdateFileForSpeaker(document);
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
            
        }

        /// <summary>
        /// Returns speaker by ID
        /// </summary>
        /// <param name="speakerId"></param>
        /// <returns>Speaker</returns>
        public Speaker GetSpeakerById(Guid speakerId)
        {
            var speakerDataProvider = new SpeakerDataManagement();
            try
            {
                return speakerDataProvider.GetSpeakerById(speakerId);
            }
            catch (Exception ex)
            {
                
                log.Error(ex);
                throw;
            }
          

        }
        
        /// <summary>
        /// Returns resume for speaker with id passed in parametars
        /// </summary>
        /// <param name="speakerId"></param>
        /// <returns></returns>
        public Domain.File GetFileForSpeaker(Guid speakerId)
        {
            var speakerDataProvider = new SpeakerDataManagement();
            try
            {
                return speakerDataProvider.GetFileForSpeaker(speakerId);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }
            

        }

        /// <summary>
        /// Returns image for speaker with id passed in parametars
        /// </summary>
        /// <param name="speakerId"></param>
        /// <returns></returns>
        public Domain.File GetImageForSpeaker(Guid speakerId)
        {
            var speakerDataProvider = new SpeakerDataManagement();
            try
            {
                return speakerDataProvider.GetImageForSpeaker(speakerId);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }
            

        }

        public List<Speaker> GetSpeakersByName(string speakerName)
        {
            var speakerDataProvider = new SpeakerDataManagement();
            try
            {
                return speakerDataProvider.GetSpeakersByName(speakerName);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }
        }
    }
}
